package net.zjitc.io.bufferedstrem;

import com.sun.org.apache.xpath.internal.operations.String;

import java.io.*;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/10 9:11
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("请输入内容：");
        Scanner scanner = new Scanner(System.in);
        java.lang.String s=scanner.nextLine();
        OutputStream out = null;
        BufferedOutputStream bos = null;
        InputStream in = null;
        BufferedInputStream bis = null;
        try {
            out = new FileOutputStream("1.txt");
            bos = new BufferedOutputStream(out);
            byte[] b = s.getBytes();
            bos.write(b);
            bos.flush();
            /*通过字节缓冲流读取文件内容显示在控制台*/
            in = new FileInputStream("1.txt");
            bis = new BufferedInputStream(in);
            int len = 0;
          /*  while ((len = bis.read()) != -1) {
                System.out.println(len);
            }*/
           byte[] bytes=new byte[1024];
           while ((len=bis.read(bytes))!=-1){
              /* System.out.println(new String(bytes,0,len));*/
           }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                bos.close();
                out.close();
                bis.close();
                in.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}
